﻿using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System;

namespace Adalbertus.BudgetPlanner.Domain
{
    public class BudgetPlan
    {
        public virtual int Id { get; private set; }
        public virtual CashFlow Flow { get; set; }
        public virtual IList<BudgetPlanDetail> Details { get; private set; }
        public virtual Budget Budget {get; set;}

        public BudgetPlan()
        {
            Details = new List<BudgetPlanDetail>();
        }

        public BudgetPlanDetail AddDetail(decimal value, string description = null)
        {
            Contract.Requires(value > 0);
            Contract.Ensures(Contract.Result<BudgetPlanDetail>() != null);
            Contract.Ensures(Contract.Result<BudgetPlanDetail>().Value == value);
            Contract.Ensures(Contract.Result<BudgetPlanDetail>().Description == description);

            BudgetPlanDetail detail = new BudgetPlanDetail
                                          {
                                              Value       = value,
                                              Description = description
                                          };
            Details.Add(detail);
            return detail;
        }

        public void Remove(BudgetPlanDetail detail)
        {
            Contract.Requires<ArgumentNullException>(detail != null, "detail");

            Details.Remove(detail);
        }
    }
}
